# 作业先完成，再完美
# 通过datetime模块完成时间戳, datetime.datetime对象, 格式化字符串三者之间的转换
from datetime import datetime
from datetime import timedelta

today = datetime.today()
now = datetime.now()
utc = datetime.utcnow()
print(f"now = {now.strftime('%Y-%m-%d %H:%M:%S')}")
print(f'utc = {utc}')

# datetime.datetime对象转化为格式化字符串
today = datetime.strftime(today, '%Y-%m-%d %H:%M:%S')
print(f"today字符串格式化 = {today}")
# 格式化字符串转化为datetime.datetime对象
today = datetime.strptime(today, '%Y-%m-%d %H:%M:%S')
# datetime.datetime对象转化为时间戳
today = datetime.timestamp(today)
print(f'today时间戳 = {today}')
# 时间戳转化为datetime.datetime对象
today = datetime.fromtimestamp(today)

# 封装一个函数get_date(day_delta), 如果传入的是-1 , 输出就是字符串日期2020-01-02.
def get_date(day_delta):
    now = datetime.now()
    now += timedelta(days = day_delta)
    print(f"传入的day_delta = {day_delta} 时,输出字符串日期 = {now.strftime('%Y-%m-%d')}")

get_date(-1)